package pluginFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

import pluginInterfaces.IPluginAlgorithm;

/**
 * Class that is used to load and retrieve Recommender plugins.
 * 
 * @author Andy Cullache
 */

public class RecommenderPluginFactory {

	
	public static final String PATH = "plugins/recommender";
	
	
	/**
	 * Gets all the objects "IPluginAlgorithm" found in the classpath. 
	 * For this you must first load the plugins from the "plugins/recommender".
	 * @return      List of plugins found and charged to the classpath.
	 */
	public static List<IPluginAlgorithm> retrieveAll() {
		List<IPluginAlgorithm> iPluginList = new ArrayList<IPluginAlgorithm>();		
		try {
			if (PluginsCharger.Charger(PATH))
			{
				ServiceLoader<IPluginAlgorithm> sl = ServiceLoader.load(IPluginAlgorithm.class);
				sl.reload();				
				for(IPluginAlgorithm pl : sl)
				{
					iPluginList.add(pl);
				}
			}
		} catch (PluginFactoryException e) {
			e.printStackTrace();
		}
	    return iPluginList;
	}

}
